package com.bosc.automationui.service;

import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.HashMap;

@Service
public class ScriptService {

    public void callScript(String jobName, String scriptId, String date) {

        HashMap<Integer, String> SCRIPT_MAPPING = new HashMap<>();

        {
            SCRIPT_MAPPING.put(0, "sh /automation/APP/templates/load_template0100.sh ");
            SCRIPT_MAPPING.put(1, "sh /automation/APP/templates/pdm_template0100.sh ");
            SCRIPT_MAPPING.put(2, "sh /automation/APP/templates/app_template0100.sh ");
            SCRIPT_MAPPING.put(3, "sh /automation/APP/templates/export_template0100.sh ");
        }

        try {
            String cmd = SCRIPT_MAPPING.get(Integer.parseInt(scriptId)) + jobName + ' ' + date;
            System.out.println("service.ScriptService -> callScript(): cmd -> " + cmd);
            Runtime.getRuntime().exec(cmd);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
